package com.example.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import java.text.SimpleDateFormat;

// 1、工人、互检 2检验 3 工艺员 4军代表 5 设计 6外协

public class UserAssignService {

    private DBOpenHelper dbHelper;
    private String username, password;
    private String datatime;
    private String tablename, usertype, systemid, signdata;
    String sqlString;

    private String gettablename(String activityname) {
        // TODO Auto-generated method stub
        if (activityname.equals("Fragment_StepContent"))
            tablename = "workingprocedure";
        else {
            if (activityname.equals("ExamItemActivity")) {
                tablename = "ExamineItem";

            } else {
                if (activityname.equals("MultMediaActivity")) {
                    tablename = "ExamItem";
                } else {
                    if (activityname.equals("PartItemActivity")) {
                        tablename = "MostPortItem";
                    }
                }

            }
        }
        return tablename;
    }


    public String getDateTime() {
        SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = sDateFormat.format(new java.util.Date());
        return date;
    }

    public UserAssignService(Context context) {
        // TODO Auto-generated constructor stub
        dbHelper = new DBOpenHelper(context);
    }

    private String getSql(String usertype, String activityname) {

        String sql = "update " + gettablename(activityname) + " set " + usertype + "= ? where systemid = ? ";
        Log.i("Tag", sql);

        return sql;
    }

    // 操作者签字Operator

    public void OperatorAssign(String systemid, String signdata,
                               String activityname) {

        Log.i("Systemid", systemid + signdata + tablename);
        usertype = "operator";
        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});


    }

    // 互检签字ReInnerChecker
    public void reInnerCheckerAssign(String systemid, String signdata,
                                     String activityname) {
        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});
        //return false;

    }

    // 检验签字 Checker
    public void CheckerAssign(String systemid, String signdata,
                              String activityname) {

        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});

        //return false;

    }

    // 工艺签字Technicr
    public void TechnicrAssign(String systemid, String signdata,
                               String activityname) {

        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});
        //return false;

    }

    // 军代表签字 Military
    public void MilitaryAssign(String systemid, String signdata,
                               String activityname) {

        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});

        //return false;

    }

    // 设计签字 Designer
    public void DesignerAssign(String systemid, String signdata,
                               String activityname) {

        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});

        //return false;

    }

    // 协作单位签字 OtherCooperator
    public void OtherCooperatorAssign(String systemid, String signdata,
                                      String activityname) {

        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        sqlString = getSql(usertype, activityname);
        sdb.execSQL(sqlString, new String[]{signdata, systemid});

    }


}
